package main

import (
  "io"
  "bytes"
  "net/url"
  "net/http"
)

func sendQiNiuRequest(cfg *CLI, method, path, rawQuery string, body []byte) (*http.Response, error) {
  u := &url.URL{
    Scheme:   "https",
    Host:     "api.qiniu.com",
    Path:     path,
    RawQuery: rawQuery,
  }

  req := &http.Request{
    Method: method,
    URL:    u,
    Header: make(http.Header),
    Body:   nil,
  }

  if (method == http.MethodPost || method == http.MethodPut) && body != nil {
    req.Body = io.NopCloser(bytes.NewReader(body))
    req.Header.Set("Content-Type", "application/json")
  }

  client := NewQiNiuClient(cfg)
  return client.Do(req)
}

